home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
pyxmpp
/
utils.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
2KB
|
66 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
__revision__ = '$Id: utils.py 647 2006-08-26 18:27:39Z jajcus $'
__docformat__ = 'restructuredtext en'
import sys
if sys.hexversion < 33751040:
raise ImportError, 'Python 2.3 or newer is required'
import time
import datetime
def to_utf8(s):
if s is None:
return None
elif type(s) is unicode:
return s.encode('utf-8')
elif type(s) is str:
return s
else:
return unicode(s).encode('utf-8')
def from_utf8(s):
if s is None:
return None
elif type(s) is unicode:
return s
elif type(s) is str:
return unicode(s, 'utf-8')
else:
return unicode(s)
minute = datetime.timedelta(minutes = 1)
nulldelta = datetime.timedelta()
def datetime_utc_to_local(utc):
ts = time.time()
cur = datetime.datetime.fromtimestamp(ts)
cur_utc = datetime.datetime.utcfromtimestamp(ts)
offset = cur - cur_utc
t = utc
d = datetime.timedelta(hours = 2)
while d > minute:
local = t + offset
tm = local.timetuple()
tm = tm[0:8] + (0,)
ts = time.mktime(tm)
u = datetime.datetime.utcfromtimestamp(ts)
diff = u - utc
if diff < minute and diff > -minute:
break
if diff > nulldelta:
offset -= d
else:
offset += d
d /= 2
return local
def datetime_local_to_utc(local):
ts = time.mktime(local.timetuple())
return datetime.datetime.utcfromtimestamp(ts)